package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.account.CheckingAccount;
import com.acme.bankapp.domain.bank.account.SavingsAccount;
import com.acme.bankapp.domain.bank.client.Client;
import com.acme.bankapp.domain.bank.client.ClientRegistrationListener;
import com.acme.bankapp.domain.bank.client.Gender;

public class BankApplication {

	public static final double MAX_BALANCE = 100;
	
	enum TypeOperation {
		DEPOSIT_OF_FUNDS,
		WITHDRAWAL_OF_FUNDS
	}
	
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		Bank someBank = new Bank(new ClientRegistrationListener[] { new Bank.PrintClientListener() });
		someBank.addListener(someBank.new EmailNotificationListener());
		
		try
		{
			Client client = new Client("First", Gender.MALE);
			client.addAccount(new SavingsAccount(23.4));
			client.addAccount(new CheckingAccount(5, 4.6));
			client.addAccount(new CheckingAccount(4.5, 1.6));
			BankService.addClient(someBank, client);
			client = new Client("Second", Gender.FEMALE);
			client.addAccount(new SavingsAccount(21.3));
			client.addAccount(new CheckingAccount(13.5, 10));
			client.addAccount(new SavingsAccount(3.4));
			BankService.addClient(someBank, client);
		} catch (Exception exception) {
			System.out.println(exception.getMessage());
		}
		BankService.printBalance(someBank);
		BankService.printMaximumAmountToWithdraw(someBank);
	}
	
	public static void modifyBank(Bank bank, int clientId, int accountId, TypeOperation type, double diffBalance) {
		try {
			switch (type) {
			case DEPOSIT_OF_FUNDS:
				bank.getClients()[clientId].getAccounts()[accountId].deposit(diffBalance);
				break;
			case WITHDRAWAL_OF_FUNDS:
				bank.getClients()[clientId].getAccounts()[accountId].withdraw(diffBalance);
			}
		} catch (Exception exception) {
			System.out.println(exception.getMessage());
		}
	}
}
